#include <iostream>
#include "DoubleLinkedList.h"


/// @brief 查找链表中是否存在给定值
/// @tparam DT 为模板
/// @param _list 链表
/// @param _val 给定值
/// @return 若存在，返回对应点迭代器的值，否则返回tail的迭代器值
template<typename DT>
typename DoubleLinkedList<DT>::iterator find(DoubleLinkedList<DT>& _list,DT& _val)
{
    typename DoubleLinkedList<DT>::iterator itr = _list.begin();
    while(*itr != _val && itr != _list.end())
        itr++;
    if(itr == _list.end()) 
    {
    	std::cout << _val << " is Not Found" << std::endl; 
    	return itr;
    }
    else
    	return itr;
}



int main(){
    
    DoubleLinkedList<int> L;

    for(int i = 1;i <= 5; i++)
        L.push_back(i);
    
    L.printList();

    DoubleLinkedList<int>::iterator itr;
    
    int x = 3;
    itr = find(L,x);

    L.erase(itr);

  
    L.printList();

    itr = find(L,x);
    
    return 0;

}
